package com.learn.rabbitmq.eight.ttl;

import com.learn.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BasicProperties;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * 死信队列
 *
 * 生产者
 */
public class Producer01TTL {
    //普通交换机
    public static final String NORMAL_EXCHANGE = "normal_exchange";
    //普通队列
    public static final String NORMAL_QUEUE = "normal_queue";
    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();


        /**
         *
         * 不影响消费者杀死队列
         *
         */
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        channel.queueBind(NORMAL_QUEUE,NORMAL_EXCHANGE,"zhangsan");

        //死信消息 设置TTL时间 ms
        AMQP.BasicProperties properties=new AMQP.BasicProperties()
                .builder()
                .expiration("10000")
                .build();
        //channel.queueDeclare();

        for (int i = 1; i <= 10; i++) {
            String message="info"+i;
            channel.basicPublish(NORMAL_EXCHANGE,
                    "zhangsan",
                    properties,
                    message.getBytes(StandardCharsets.UTF_8));

        }


    }
}
